package com.deere.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.deere.model.enums.WorkOrderStatus;

/**
 * 工单
 * 
 * @author zhaohongxing
 * 
 */
@Entity
@Table(name = "WORK_ORDER")
public class WorkOrder extends GenericModel implements Cloneable{
	/*
	 * 主键
	 */
	private int id;
	/*
	 * 工单批次号。
	 * 每个零件进行加工生产时，一般都会有多个工序，需要用此批次号来唯一标识出零件当前加工过程中的整个工序集合。
	 * 此批次号格式为：yyyyMMddHHmmssS。为了避免冲突
	 */
	private String batchNum;
	/*
	 * 此字段用来确定工序在零件整个加工工序的位置，即第几道工序
	 */
	private int sequence;
	
	/*
	 * 姓名
	 */
	private String workerName;
	/*
	 * 零件图号
	 */
	private String partCode;
	/*
	 * 零件名称
	 */
	private String partName;
	/*
	 * 工作单对应的工序编号
	 */
	private String wpCode;
	/*
	 * 与之相关的生产计划单
	 */
	private String planOrder;
	/*
	 * 此工作单完成的数量
	 */
	private int quantity;
	/***********首检数据***********/
	/*
	 * 首检员
	 */
	private String firstInspectionName;
	/*
	 * 首检时间
	 */
	private String firstInspectionTime;
	/*************检验数据***************/
	/*
	 * 单件工时
	 */
	private float manHours;
	/*
	 * 此工作单合格的数量
	 */
	private int qualifiedQuantity;
	/*
	 * 完工时间
	 */
	private String completeDate;
	
	/*
	 * 检验员
	 */
	private String qualityInspector;
	/*
	 * 收检人
	 */
	private String receivingInspection;
	/*
	 * 收检时间
	 */
	private String receivingInspectionDate;
	/*
	 * 车间主任
	 */
	private String workshopLeader;
	/*
	 * 工作单的状态。 此字段用来跟踪工作单的状态，用状态来控制工作单在不同环节的流转，实现工作流的效果。
	 */
	private String status;
	
	/*
	 * 流水发生的日期
	 */
	private Date workOrderDate = new Date();
	
	private ItemWorkflow itemWorkflow;
	/*
	 * 对应的工序对象
	 */
	private WorkingProcedure procedure;
	/*
	 * 此工作单对应的计划单
	 * 
	 */
	private ProductionOrderItem productionOrderItem;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getSequence() {
		return sequence;
	}

	public void setSequence(int sequence) {
		this.sequence = sequence;
	}

	public String getFirstInspectionName() {
		return firstInspectionName;
	}

	public void setFirstInspectionName(String firstInspectionName) {
		this.firstInspectionName = firstInspectionName;
	}

	public String getFirstInspectionTime() {
		return firstInspectionTime;
	}

	public void setFirstInspectionTime(String firstInspectionTime) {
		this.firstInspectionTime = firstInspectionTime;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getWorkerName() {
		return workerName;
	}

	public void setWorkerName(String workerName) {
		this.workerName = workerName;
	}

	public String getPartCode() {
		return partCode;
	}

	public void setPartCode(String partCode) {
		this.partCode = partCode;
	}

	public String getPartName() {
		return partName;
	}

	public void setPartName(String partName) {
		this.partName = partName;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public String getBatchNum() {
		return batchNum;
	}

	public void setBatchNum(String batchNum) {
		this.batchNum = batchNum;
	}

	public String getPlanOrder() {
		return planOrder;
	}

	public void setPlanOrder(String planOrder) {
		this.planOrder = planOrder;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false)
	public Date getWorkOrderDate() {
		return workOrderDate;
	}

	public void setWorkOrderDate(Date workOrderDate) {
		this.workOrderDate = workOrderDate;
	}

	public String getQualityInspector() {
		return qualityInspector;
	}

	public void setQualityInspector(String qualityInspector) {
		this.qualityInspector = qualityInspector;
	}

	/**
	 * @see WorkOrderStatus
	 * @return
	 */
	@Column(name = "STATUS", nullable = true, columnDefinition = "VARCHAR(15) default 'NEW'")
	public String getStatus() {
		return status;
	}

	public int getQualifiedQuantity() {
		return qualifiedQuantity;
	}

	public void setQualifiedQuantity(int qualifiedQuantity) {
		this.qualifiedQuantity = qualifiedQuantity;
	}

	@Column(name="completeDate")
	public String getCompleteDate() {
		return completeDate;
	}

	public void setCompleteDate(String completeDate) {
		this.completeDate = completeDate;
	}

	public float getManHours() {
		return manHours;
	}

	public void setManHours(float manHours) {
		this.manHours = manHours;
	}

	public String getReceivingInspection() {
		return receivingInspection;
	}

	public void setReceivingInspection(String receivingInspection) {
		this.receivingInspection = receivingInspection;
	}

	public String getReceivingInspectionDate() {
		return receivingInspectionDate;
	}

	public void setReceivingInspectionDate(String receivingInspectionDate) {
		this.receivingInspectionDate = receivingInspectionDate;
	}

	public String getWorkshopLeader() {
		return workshopLeader;
	}

	public void setWorkshopLeader(String workshopLeader) {
		this.workshopLeader = workshopLeader;
	}

	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="wpCode",insertable=false,updatable=false)
	public WorkingProcedure getProcedure() {
		return procedure;
	}

	public void setProcedure(WorkingProcedure procedure) {
		this.procedure = procedure;
	}

	public String getWpCode() {
		return wpCode;
	}

	public void setWpCode(String wpCode) {
		this.wpCode = wpCode;
	}

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="itemId")
	public ProductionOrderItem getProductionOrderItem() {
		return productionOrderItem;
	}

	public void setProductionOrderItem(ProductionOrderItem productionOrderItem) {
		this.productionOrderItem = productionOrderItem;
	}

	/**
	 * TODO 这个顺序如果确定？？？？
	 */
	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumns({@JoinColumn(name="partCode",insertable=false,updatable=false),@JoinColumn(name="sequence",insertable=false,updatable=false),@JoinColumn(name="wpCode",insertable=false,updatable=false)})
	public ItemWorkflow getItemWorkflow() {
		return itemWorkflow;
	}

	public void setItemWorkflow(ItemWorkflow itemWorkflow) {
		this.itemWorkflow = itemWorkflow;
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	
}
